package com.huashizhaoxi.lionapp.dao;

import com.huashizhaoxi.lionapp.entity.FruitItem;
import com.huashizhaoxi.lionapp.entity.FruitKind;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FruitMapper {

    @Insert("insert into fruit_buy(title, info, price, discount_price, pic_url, fruit_buy_kind_id, sell_count) values(#{title}, #{info}, #{price}, #{discount_price}, #{pic_url}, #{fruit_buy_kind_id}, #{sell_count})")
    int addFruitItem(FruitItem fruitItem);


    @Select("select * from fruit_buy_kind")
    List<FruitKind> getFruitKind();

    @Select("select * from fruit_buy order by id desc")
    List<FruitItem> getFruitItem();

    @Select("select * from fruit_buy where fruit_buy_kind_id = #{fruit_buy_kind_id} order by id desc")
    List<FruitItem> getFruitItemByKind(int fruitKindId);

    @Select("select * from fruit_buy_kind where status > 0 order by status asc")
    List<FruitKind> getValidFruitKind();

    @Insert("insert into fruit_buy_kind(name, status) values(#{name}, #{status})")
    int addFruitKind(FruitKind fruitKind);

    @Delete("delete from fruit_buy where id = #{id}")
    int deleteFruitItem(int id);

    @Delete("delete from fruit_buy where fruit_buy_kind_id = #{id}")
    void deleteFruitItemByKindId(int id);

    @Delete("delete from fruit_buy_kind where id = #{id}")
    void deleteFruitKind(int id);

    @Update("update fruit_buy_kind set name = #{name}, status = #{status} where id = #{id}")
    void reviseFruitKind(FruitKind fruitKind);

    @Update("update fruit_buy set title = #{title}, info = #{info}, price = #{price}, discount_price = #{discount_price}, pic_url = #{pic_url}, fruit_buy_kind_id = #{fruit_buy_kind_id} where id = #{id}")
    void reviseFruitItem(FruitItem fruitItem);
}
